extends Control

@export_group("UI")
@export var character_name_text : Label
@export var text_box : Label
@export var left_avatar : TextureRect
@export var right_avatar : TextureRect

@export_group("对话")
@export var main_dialogue : DialogueGroup

var index : int = 0

func talk():
	var dialogue := main_dialogue.dialogue_list[index]
	character_name_text.text = dialogue.character_name
	text_box.text = dialogue.content
	
	if dialogue.show_on_left:
		left_avatar.texture = dialogue.avatar
		right_avatar.texture = null
	else:
		left_avatar.texture = null
		right_avatar.texture = dialogue.avatar
	
	index += 1

func _ready() -> void:
	talk()


func _on_margin_container_gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_MASK_LEFT and event.is_pressed():
		talk()
